﻿
    using Maticsoft.BLL;
    using Maticsoft.Model;

    using System;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public partial class WebPage_Tongji_User : SystemBBasePage
    {
        private Maticsoft.Model.Category cate = new Maticsoft.Model.Category();
        private Maticsoft.BLL.Category cateList = new Maticsoft.BLL.Category();

        private int index = Convert.ToInt32(PageIndex.pageIndex);

        private string sql = " 1=1 ";
        protected string today = DateTime.Now.ToString("yyyy-MM-dd");
        protected string Tommorew = DateTime.Now.AddDays(1.0).ToString("yyyy-MM-dd");
        private Maticsoft.Model.UserInfo user = new Maticsoft.Model.UserInfo();
        private Maticsoft.BLL.UserInfo userList = new Maticsoft.BLL.UserInfo();
        protected string zuo = DateTime.Now.AddDays(-1.0).ToString("yyyy-MM-dd");

        protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
        {
            this.sql = string.Concat(new object[] { this.sql, " and  Id not in(select top ", (e.NewPageIndex - 1) * this.index, " Id from [User] where ", this.sql, " order by Id desc ) " });
            try
            {
                this.getValue(this.index, 10, this.sql);
            }
            catch (Exception)
            {
                this.SetError("您填写的时间格式有错误,请重新填写");
            }
        }

        private void getName()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<tr >");
            builder.Append("<td width='20px'>ID</td>");
            builder.Append("<td width='200px'>Email/用户名</td>");
            builder.Append("<td width='100px' nowrap>姓名/城市</td>");
            builder.Append("<td width='120px'>注册时间</td>");
            builder.Append("<td width='200px'>来源地址</td>");
            builder.Append("<td width='100px'>联系电话</td>");
            builder.Append("<td width='160px'>操作</td>");
            builder.Append("</tr>");
            this.Literal1.Text = builder.ToString();
        }

        private void getState()
        {
            if (this.Session["value"] == null)
            {
                this.sql = this.sql ?? "";
            }
            else
            {
                this.sql = this.Session["value"].ToString();
                if ((((this.Session["zuo"] != null) && (this.Session["today"] != null)) && (this.Session["zuo"].ToString() != "")) && (this.Session["today"].ToString() != ""))
                {
                    this.zuo = this.Session["zuo"].ToString();
                    this.today = this.Session["today"].ToString();
                }
            }
        }

        private void getValue(int index, int page, string str)
        {
            StringBuilder builder = new StringBuilder();
            int num = 0;
            foreach (Maticsoft.Model.UserInfo info in this.userList.GetList(index, page, str))
            {
                if ((num % 2) != 0)
                {
                    builder.Append("<tr>");
                }
                else
                {
                    builder.Append("<tr class='alt'>");
                }
                num++;
                builder.Append("<td>" + info.Id + "</td>");
                builder.Append("<td>");
                if (info.Email != "")
                {
                    builder.Append(info.Email + "/");
                }
                else
                {
                    builder.Append("&nbsp;/");
                }
                builder.Append(info.Username ?? "");
                builder.Append("</td>");
                this.cate = this.cateList.GetModel(info.City_id);
                if ((info.Realname != "") && (this.cate != null))
                {
                    builder.Append("<td>" + info.Realname + "/" + this.cate.Name + "</td>");
                }
                else if ((info.Realname == "") && (this.cate != null))
                {
                    builder.Append("<td>" + this.cate.Name + "</td>");
                }
                else if ((info.Realname != "") && (this.cate == null))
                {
                    builder.Append("<td>" + info.Realname + "</td>");
                }
                else
                {
                    builder.Append("<td>&nbsp;</td>");
                }
                builder.Append("<td>" + info.Create_time + "</td>");
                if (info.IP_Address != "")
                {
                    if (info.IP_Address.Trim() == "直接输入网址")
                    {
                        builder.Append("<td style='color:red;'>直接输入网址</td>");
                    }
                    else
                    {
                        builder.Append("<td><div style='width:140px; overflow: hidden;'><a target='_blank' href='" + info.IP_Address + "' alt='" + info.IP_Address + "'>" + info.IP_Address + "</a></td></td>");
                    }
                }
                else
                {
                    builder.Append("<td>&nbsp;</td>");
                }
                if (info.Mobile != "")
                {
                    builder.Append("<td>" + info.Mobile + "</td>");
                }
                else
                {
                    builder.Append("<td>&nbsp;</td>");
                }
                builder.Append("<td>");
                builder.Append("<a class='ajaxlink' href='/ajax/manage.aspx?action=userview&Id=" + info.Id + "'>详情</a>");
                builder.Append("</td>");
            }
            this.Literal2.Text = builder.ToString();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "tongji";
            this.getName();
            if (!base.IsPostBack)
            {
                this.sql = this.sql ?? "";
                if (((this.Session["zuo"] != null) && (this.Session["today"] != null)) && (this.Session["value"] != null))
                {
                    this.Session.Remove("zuo");
                    this.Session.Remove("today");
                    this.Session.Remove("value");
                }
            }
            else if (base.Request.HttpMethod == "POST")
            {
                this.setState();
                this.getState();
            }
            try
            {
                this.getValue(this.index, 10, this.sql);
                this.pageSum(this.sql, this.index);
            }
            catch (Exception)
            {
                this.SetError("您填写的时间格式有错误,请重新填写");
            }
        }

        private void pageSum(string where, int count)
        {
            this.AspNetPager1.AlwaysShow = true;
            this.AspNetPager1.CurrentPageIndex = 1;
            this.AspNetPager1.PageSize = count;
            this.AspNetPager1.RecordCount = this.userList.GetModelList(where).Count;
            this.AspNetPager1.DataBind();
        }

        private void setState()
        {
            string sql;
            if ((base.Request.Form["today"] != null) && (base.Request.Form["today"].ToString() != ""))
            {
                sql = this.sql;
                this.sql = sql + " and Create_time between '" + this.today + "' and '" + this.Tommorew + "'  ";
                this.Session.Add("value", this.sql);
                this.Session.Add("zuo", this.zuo);
            }
            if ((base.Request.Form["beforeDay"] != null) && (base.Request.Form["beforeDay"].ToString() != ""))
            {
                sql = this.sql;
                this.sql = sql + " and Create_time between '" + this.zuo + "' and '" + this.today + "'  ";
                this.Session.Add("value", this.sql);
                this.Session.Add("today", this.today);
            }
            if ((((base.Request.Form["search"] != null) && (base.Request.Form["before"] != null)) && ((base.Request.Form["last"] != null) && (base.Request.Form["before"].ToString() != ""))) && (base.Request.Form["last"].ToString() != ""))
            {
                sql = this.sql;
                this.sql = sql + " and Create_time between '" + base.Request.Form["before"].ToString() + " 00:00:01' and '" + base.Request.Form["last"].ToString() + " 23:59:59' ";
                this.Session.Add("value", this.sql);
                this.Session.Add("zuo", base.Request.Form["before"].ToString());
                this.Session.Add("today", base.Request.Form["last"].ToString());
            }
        }
    }

